package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException {
        Student s=new Student("张三",18,"男");
        System.out.println(s);
        Class cls=Class.forName("reflect.Student");
        Constructor c=cls.getConstructor(String.class,int.class,String.class);
        Object obj=c.newInstance("张三",18,"男");
        System.out.println(obj);

        Constructor c2=cls.getConstructor(String.class,int.class,String.class);
        Object obj2=c2.newInstance("王五","30","女");
        System.out.println(obj2);
    }
}
